package com.cloud.bc.service.impl;

import com.cloud.bc.model.entity.BcLikes;
import com.cloud.bc.mapper.BcLikesMapper;
import com.cloud.bc.model.entity.BcSingles;
import com.cloud.bc.service.BcLikesService;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.util.List;

/**
 * 喜欢
 *
 * @author douhaichao code generator
 * @date 2021-01-09 19:24:09
 */
@Service
@AllArgsConstructor
public class BcLikesServiceImpl extends ServiceImpl<BcLikesMapper, BcLikes> implements BcLikesService {

    /**
     * 根据对象属性查找满足条件的第一条数据     *      * @return
     */
    @Override
    public BcLikes selectOne(BcLikes req) {
        QueryWrapper queryWrapper = new QueryWrapper<BcLikes>();
        queryWrapper.setEntity(req);
        return baseMapper.selectOne(queryWrapper);
    }

    /**
     * 根据条件查询所有
     */
    @Override
    public List<BcLikes> selectAll(BcLikes req) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.setEntity(req);
        return baseMapper.selectList(queryWrapper);
    }

    /**
     * 根据对象查询所有分页数据(精确查询)     *      * @return
     */
    @Override
    public IPage<BcLikes> selectPage(Page page, BcLikes req) {
        IPage<BcLikes> list = baseMapper.selectPage(
                page,
                new QueryWrapper<BcLikes>().setEntity(req));
        return list;
    }

    /**
     * 根据对象查询所有分页数据(模糊查询)     *      * @return
     */
    @Override
    public IPage<BcLikes> selectPageByLike(Page page, BcLikes req) {
        QueryWrapper queryWrapper = new QueryWrapper();

        if (null != req.getId()) {
            queryWrapper.eq("id", req.getId());
        }

        if (null != req.getUserId()) {
            queryWrapper.eq("user_id", req.getUserId());
        }

        if (null != req.getTargetId()) {
            queryWrapper.eq("target_id", req.getTargetId());
        }

        if (null != req.getCreateTime()) {
            queryWrapper.eq("create_time", req.getCreateTime());
        }
        IPage<BcLikes> list = baseMapper.selectPage(page, queryWrapper);
        return list;
    }

    /**
     * 根据条件统计数据量     *      * @return
     */
    @Override
    public int count(BcLikes req) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.setEntity(req);
        return baseMapper.selectCount(queryWrapper);
    }

    @Override
    public List<BcSingles> selectMyLike(Page p, Integer userId) {
        return baseMapper.selectMyLike(p, userId);
    }

    @Override
    public List<BcSingles> selectLikeMe(Page p, Integer userId) {
        return baseMapper.selectLikeMe(p, userId);
    }

    @Override
    public List<BcSingles> selectMutual(Page p, Integer userId) {
        return baseMapper.selectMutual(p, userId);
    }
}
